/**
 * 	 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *   @author Colin Redmond
 *   Copyright (C) 2011 Colin Redmond
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package com.cred.industries.platform.converter;

import java.util.ArrayList;
import java.util.List;

import com.cred.industries.platform.business.objects.CustomerBO;
import com.cred.industries.platform.transferObj.CustomerTrans;
import com.cred.industries.platform.transferObj.DetailedCustomerTrans;

/**
 * Converts customers from transfer objects to business objects and back
 */
public final class CustomerConverter {

	/**
	 * The constructor is private since this is a utility class 
	 * that does not need to be instantiated 
	 */
	private CustomerConverter() {
		
	}
	/**
	 * Converts from a BO to a trans
	 * @param custBO customer BO
	 * @return customer transfer object
	 */
	public static CustomerTrans convert(CustomerBO custBO) {
		
		if(custBO.getCustomerId()  <= 0) {
			return null;
		}
		
		CustomerTrans custTrans = new CustomerTrans(custBO.getCustomerId(), custBO.getPersonaName());
		
		return custTrans;
	}
	
	/**
	 * Converts from a list of BO to a list of trans
	 * @param custBO list of customer BO
	 * @return list of customer transfer object
	 */
	public static List<CustomerTrans> convert(List<CustomerBO> custBO) {
		
		if (custBO.size() == 0) {
			return null;
		}
		
		List<CustomerTrans> custsTrans = new ArrayList<>();
		for (CustomerBO i : custBO) {
			custsTrans.add(convert(i));
		}
		return custsTrans;		
	}
	
	/**
	 * converts from a BO to a detailed Trans
	 * @param custBO customer BO
	 * @return a detailed transfer object
	 */
	public static DetailedCustomerTrans convertDetailed(CustomerBO custBO) {
		
		if (custBO.getCustomerId() <= 0)
			return null;
		
		DetailedCustomerTrans custTrans = new DetailedCustomerTrans(custBO.getCustomerId()
													, custBO.getPersonaName()
													, custBO.getPassword()
													, custBO.getFirstName()
													, custBO.getLastName()
													, custBO.getEmailAddress());
			
		return custTrans;
	}
	
	/**
	 * converts from a detailed customer transfer object to a BO
	 * @param custTrans detailed customer transfer object
	 * @return customre BO
	 */
	public static CustomerBO convert(DetailedCustomerTrans custTrans) {
		
		CustomerBO custBO = new CustomerBO(custTrans.getCustomerId()
											, custTrans.getPersonaName()
											, custTrans.getPassword()
											,custTrans.getFirstName()
											, custTrans.getLastName()
											, custTrans.getEmailAddress());			
		return custBO;
	}
}
